import java.util.Arrays;

import static java.lang.System.out;

public class GenerateCapturedPattern {
    public static final void main(String[] args) {
        if (args.length > 0 && args[0].equals("c")) {
            capturedMask();
        } else {
            loopMask();
        }
    }

    public static final int[] JUMPING_LOOP4 = {
        0x20502,   0x40A04,   0x205020,   0x40A040,
        0x2050200, 0x40A0400, 0x20502000, 0x40A04000,
    };

    public static final int[] CAPTURED_LOOP4 = {
        0x6060,   0xC0C0,   0x30300,   0x60600,
        0x606000, 0xC0C000, 0x3030000, 0x6060000,
    };

    public static final int[][] JUMPING_SQUARES4 = {
        { 2,  9, 18, 11},
        { 3, 10, 19, 12},
        { 6, 13, 22, 15},
        { 7, 14, 23, 16},
        {10, 17, 26, 19},
        {11, 18, 27, 20},
        {14, 21, 30, 23},
        {15, 22, 31, 24},
    };

    public static final int[] JUMPING_LOOP6 = {
        0x40A0502, 0x40A05020, 0x2050A04, 0x2050A040,
    };

    public static final int[][] JUMPING_SQUARES6 = {
        { 2,  9, 18, 27, 20, 11},
        { 6, 13, 22, 31, 24, 15},
        { 3, 10, 17, 26, 19, 12},
        { 7, 14, 21, 30, 23, 16},
    };

    public static final int[] CAPTURED_LOOP6 = {
        0xC0A060, 0x6050300, 0x60A0C0, 0x3050600,
    };

    public static void loopMask() {
        Board board = new Board();
        for (int i = 0; i < JUMPING_LOOP4.length; i++) {
            out.println("Move: " + Arrays.toString(JUMPING_SQUARES4[i]));
            board.white = JUMPING_LOOP4[i];
            board.black = CAPTURED_LOOP4[i];
            GameEngine.printBoard(board);
        }
        for (int i = 0; i < JUMPING_LOOP6.length; i++) {
            out.println("Move: " + Arrays.toString(JUMPING_SQUARES6[i]));
            board.white = JUMPING_LOOP6[i];
            board.black = CAPTURED_LOOP6[i];
            GameEngine.printBoard(board);
        }
    }

    public static void capturedMask() {
        boolean[][] board = new boolean[10][10];

        for (int row = 0; row < 10; row++) {
            for (int col = 0; col < 10; col++) {
                board[row][col] = false;
            }
        }

        out.println("    private static final int[] capturedMask = {");

        for (int row = 1; row <= 8; row++) {
            out.print("       ");

            int startCol = (row & 1) + 1;
            for (int col = startCol; col <= 8; col += 2) {
                board[row - 1][col - 1] = true;
                board[row - 1][col + 1] = true;
                board[row + 1][col - 1] = true;
                board[row + 1][col + 1] = true;
                printMask(board);
                board[row - 1][col - 1] = false;
                board[row - 1][col + 1] = false;
                board[row + 1][col - 1] = false;
                board[row + 1][col + 1] = false;
            }
            out.println();
        }

        out.println("    };");
    }

    public static void printMask(boolean[][] board) {
        int mask = 0;

        int bitNbr = 0;
        for (int row = 1; row <= 8; row++) {
            int startCol = (row & 1) + 1;
            for (int col = startCol; col <= 8; col += 2) {
                int bit = 1 << bitNbr;
                if (board[row][col]) {
                    mask |= bit;
                }
                bitNbr++;
            }
        }

        out.printf(" 0x%08x,", mask);
    }
}
